﻿Imports System.Data.SqlClient
Public Class frm_E_Detallado

    Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
        Close()
    End Sub
    Sub CargaDetallado()
        Dim FechaInicial As String = frmE_Evaluacion.datFechaInicial.Value.ToString("MM/dd/yyyy")
        Dim FechaFinal As String = frmE_Evaluacion.datFechaFinal.Value.ToString("MM/dd/yyyy")

        Dim cnConn As New SqlConnection
        Dim strSql As String
        Dim cmdBuscar As New SqlCommand
        Dim rdBuscar As SqlDataReader

        Dim Total As Double = 0
        Dim Fecha As Date

        Try
            cnConn.ConnectionString = CitraConnection
            strSql = "SELECT * FROM E_MatrizEvaluacion WHERE CONVERT(VARCHAR,Fecha,101)>='" & FechaInicial & "' AND CONVERT(VARCHAR,Fecha,101)<='" & FechaFinal & "' AND IdOperador=" & txtIDOperador.Text & " ORDER BY Fecha"

            cmdBuscar.Connection = cnConn
            cmdBuscar.CommandText = strSql

            cnConn.Open()
            rdBuscar = cmdBuscar.ExecuteReader

            Do While rdBuscar.Read()
                Fecha = rdBuscar("Fecha")
                dgDetallado.Rows.Add(Fecha.ToShortDateString, rdBuscar("NoEconomico").ToString.Trim, rdBuscar("Servicios") / 100, rdBuscar("Puntualidad") / 100, rdBuscar("Presentacion") / 100, rdBuscar("Rendimiento") / 100, rdBuscar("Ventas") / 100, rdBuscar("Bloqueos") / 100, rdBuscar("Total") / 100, 150 * (rdBuscar("Total") / 100))
            Loop

            For i = 0 To dgDetallado.Rows.Count - 1
                Total = Total + dgDetallado.Rows(i).Cells(9).Value

            Next

            txtTotal.Text = Total

        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try

        For i = 2 To 9
            dgDetallado.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            dgDetallado.Columns(i).DefaultCellStyle.Format = "0.00%"
        Next

        dgDetallado.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        dgDetallado.Columns(9).DefaultCellStyle.Format = "##,##0.0"

        txtTotal.Text = Format(CDbl(txtTotal.Text), "##,##0.0")
    End Sub
    

       

    Private Sub frm_E_Detallado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ToolStrip1.Cursor = Cursors.Hand
        ToolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System

        CargaDetallado()

    End Sub

    Private Sub VerDetalleDeConceptosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VerDetalleDeConceptosToolStripMenuItem.Click
        Dim Fecha As Date = CDate(dgDetallado.CurrentRow.Cells(0).Value)
        frmE_DetalleDia.datFecha1.Value = Fecha
        frmE_DetalleDia.Text = Me.Text
        frmE_DetalleDia.ShowDialog()
    End Sub
End Class